import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const PreviewImage 			= $Lazy.state(()=>import('#private/pages/preview-image'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
//
const UploadImgModal 		= $Lazy.state(()=>import('./cpt/upload-img-modal'))
const RelevanceImgModal 	= $Lazy.state(()=>import('./cpt/relevance-img-modal'))
const AuditImgModal 		= $Lazy.state(()=>import('./cpt/audit-img-modal'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '选择状态',		name: 'status',	type: 'select', loading:true, idStr:'code' },
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
		  this.fetch()
		}
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 选择状态
			$fn.setRow( forms, 'status', await f.getDicCache({ code:43700 } ) )
			// 
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'app-upload-pic/index')
	
	// 表单
	cols = [
		{ title: '条码号',		dataIndex: 'spec_code', 		width:150 },
		{ title: '图片编码', 	dataIndex: 'pic_name', 		width:200 },
		{ title: '上传时间', 	dataIndex: 'created_at', 		width:150 },
		{ title: '上传人', 		dataIndex: 'operator_name', 	width:150 },
		{ title: '状态',		dataIndex: 'pic_status_name', 	...$fn.table.status },
		{ title: '审核备注', 	dataIndex: 'audit_remark', 		width:150 },
		TableControls.controls.call(this,{ width: 150 })
	]
	// 表格操作按钮
	table_controls = (text,{ uuid,pic_path}) => {
		return [
			TableControls.click.call(this, '查看', ()=>{this.previewImage.open(pic_path)}, { ghost:true } ),					// 查看
			// 删除
			TableControls.del.call(this, { param:{uuid}, api:'app-upload-pic/del', refresh:true})																			// 删除
		]
	}
	// 操作按钮
	controls = () => {
		return [
			Controls.click.call(this, '图片上传', ()=> this.uploadImgModal.open() ),
			Controls.click.call(this, '条码关联', ()=> this.relevanceImgModal.open() ),
			Controls.click.call(this, '图片审核', ()=> this.auditImgModal.open() ),
		]
	}
	// 删除
	// onDel = uuid => Delete.call(this, 'app-upload-pic/del', { uuid,isKeys: !uuid })	
	
	render(){
		return (
			<>
				<Page title='申请单上传' controls={this.controls()} >
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this, { isInit: window.isInit }) }
				</Page>
				{/* 查看图片 */}
				<PreviewImage onRef	= { ref => this.previewImage = ref }/>
				{/* 图片上传 */}
				<UploadImgModal onRef	= { ref => this.uploadImgModal = ref } onRefresh={this.fetch}/>
				{/* 图片关联 */}
				<RelevanceImgModal onRef	= { ref => this.relevanceImgModal = ref } onRefresh={this.fetch}/>
				{/* 图片审核 */}
				<AuditImgModal onRef	= { ref => this.auditImgModal = ref } onRefresh={this.fetch} />
			</>
		)
	}
}

export default Index